package com.application.fabric.test;

import com.application.fabric.fabriccontrol.operate.entityfabric.BasicAsset;
import com.application.fabric.fabriccontrol.operate.entityfabric.Trademsg;
import com.application.fabric.fabriccontrol.operate.serverfabric.ServeAsset;
import com.application.fabric.fabriccontrol.operate.serverfabric.ServeAssetbasic02;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/basic02")
public class basic02 {
    @Autowired
    private ServeAsset serveAsset;

    @GetMapping("submit")
    public Map<String,Object> QueryAllAsset(@RequestBody BasicAsset basicAsset) throws Exception{
        String result = serveAsset.Submitallasset(basicAsset);
//        System.out.println(basicAsset.getId()+basicAsset.getName()+basicAsset.getAllowance()+basicAsset.getOwner()+basicAsset.getAppraisedvalue());
        Map<String,Object> map = new HashMap<>();
        map.put("code",200);
        map.put("msg","查询成功");
        map.put("data",result);
        return map;
    }


    @PostMapping("tradingassets")
    public Map<String,Object> TradingAssets(@RequestBody Trademsg trademsg) throws Exception{

        String result = serveAsset.TransferAsset(trademsg.getAssetId(),trademsg.getBuyer());
        Map<String,Object> map = new HashMap<>();
        map.put("code",200);
        map.put("msg","转让成功");
        map.put("data",result);
        return map;
    }

    @Autowired
    private ServeAssetbasic02 serveAssetbasic02;
    @GetMapping("readasset")
    public Map<String,Object> readasset(@RequestParam("assetid") String assetid) throws Exception{
        String result = serveAssetbasic02.ReadAsset(assetid);
//        System.out.println(basicAsset.getId()+basicAsset.getName()+basicAsset.getAllowance()+basicAsset.getOwner()+basicAsset.getAppraisedvalue());
        Map<String,Object> map = new HashMap<>();
        map.put("code",200);
        map.put("msg","查询成功");
        map.put("data",result);
        return map;
    }
}
